package com.huang825172.sbog.Util;

import android.content.Context;
import android.content.SharedPreferences;

import static android.content.Context.MODE_PRIVATE;

//处理缓存信息的helper
public class StatusCacheUtil {
    private String name;
    private SharedPreferences cache;

    public StatusCacheUtil(String name, Context context) {
        this.name = name;
        cache = context.getSharedPreferences(this.name, MODE_PRIVATE);
    }

    public void put(String key, String value) {
        SharedPreferences.Editor editor = cache.edit();
        editor.putString(key, value);
        editor.commit();
    }

    public void put(String key, Boolean value) {
        SharedPreferences.Editor editor = cache.edit();
        editor.putBoolean(key, value);
        editor.commit();
    }

    public void remove(String key) {
        SharedPreferences.Editor editor = cache.edit();
        editor.remove(key);
        editor.commit();
    }

    public String getAsString(String key) {
        return cache.getString(key, null);
    }

    public Boolean getAsBoolean(String key) {
        return cache.getBoolean(key, false);
    }
}
